/**
 * Copyright (c) 2021 Choice, Inc.
 * All Rights Reserved.
 * Choice Proprietary and Confidential.
 */
package cn.ruleengine.web.mq;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;

import static cn.ruleengine.web.config.rabbit.RabbitTopicConfig.FANOUT_EXCHANGE;

@Slf4j
@Component
public class RuleSetChangeProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void broadcast(String method, Object... model) {
        log.info("[MQ] RuleSetChangeProducer.broadcast begin:{}",
                DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        Map<String, Object> object = new HashMap<>();
        object.put("method", method);
        object.put("args", model);
        rabbitTemplate.convertAndSend(FANOUT_EXCHANGE, null, object);
    }
}
